package com.simple.util;

import java.util.ArrayList;
import java.util.List;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

import com.simple.util.common.ErrorUtil;
import com.simple.util.common.XSSUtil;
import com.simple.util.object.JFValidationBean;


public class ExceptionUtil{    
    public static ModelAndView handleBackException(final String siteLanguage,final Exception ex){ 
        final ModelMap model = new ModelMap();
        
        final List<JFValidationBean> errorList= new ArrayList<JFValidationBean>();
        
        ErrorUtil.addExceptionToErrorList(errorList,ex);
        
        final String errorMessage = ErrorsUtil.getJavascriptErrorMessage(siteLanguage, errorList);
        model.put("errorMessage", errorMessage);
        model.put("siteLanguage", siteLanguage);
        
        return new ModelAndView("common/defBackError", model); 
    } 
    
    public static ModelAndView handleServiceException(final String siteLanguage,final Exception ex){ 
        final ModelMap model = new ModelMap();
        
        final List<JFValidationBean> errorList= new ArrayList<JFValidationBean>();
        
        ErrorUtil.addExceptionToErrorList(errorList,ex);
        
        final String errorMessage = ErrorsUtil.getErrorMessage(siteLanguage, errorList, "");
        
        model.put("errorMessage", errorMessage);
        model.put("siteLanguage", siteLanguage);
        model.put("exception", XSSUtil.javaScriptEncode(ErrorUtil.generateStackTraceString(ex)));
        
        return new ModelAndView("common/defServiceError", model); 
    } 
}
